package main

import (
	"fmt"

	"hongen.com/go-test/array"
)

func main() {
	a := make([]int, 10)     //slice len=10,cap=10
	b := make([]int, 10, 20) //slice len=10, cap=20
	a[0] = 1
	a[3] = 12
	a[5] = 10
	array.PrintfV(a)
	fmt.Printf("\na's len=%v, cap=%v", len(a), cap(a))
	fmt.Printf("\nb's len=%v, cap=%v", len(b), cap(b))

	// [10]int 和 [20]int是不同类型
	arr1 := [10]int{}
	arr2 := [20]int{}
	arrayChangeVal(arr1)
	fmt.Printf("\nafter change val, arr1=%v", arr1) //数组作为参数只传值，不改变原始值
	//切片
	arrayChangeSlice(arr1[:])
	fmt.Printf("\nafter change slice, arr1=%v\n", arr1) //切片，可以改变值

	arrayChangeRef(&arr2)
	fmt.Printf("\nafter change ref,arr2=%v", arr2)

	var arr3 [5]int                 //初始化，所有值都为0
	arr4 := [3]int{1, 3, 5}         //长度为3的数组
	arr5 := [...]int{2, 4, 6, 8, 0} //长度让编译器自动读取
	var arr6 [4][5]int              //二维数组
	fmt.Println(arr3, arr4, arr5, arr6)

	/**
	  运行结果：
	  [1 0 0 12 0 10 0 0 0 0]
	  a's len=10, cap=10
	  b's len=10, cap=20
	  after change val [0 0 0 0 0 0 0 0 0 0]
	  after change ref [100 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
	  [0 0 0 0 0] [1 3 5] [2 4 6 8 0] [[0 0 0 0 0] [0 0 0 0 0] [0 0 0 0 0] [0 0 0 0 0]]
	*/
}
func arrayChangeSlice(arr []int) {
	arr[0] = 100
}

func arrayChangeVal(a [10]int) {
	a[0] = 100
}

func arrayChangeRef(a *[20]int) {
	a[0] = 100
}
